package com.tanhua.dubbo.api.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.domain.db.Options;
import com.tanhua.dubbo.api.OptionsApi;
import com.tanhua.dubbo.api.TopicApi;
import com.tanhua.dubbo.mapper.OptionsMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service(timeout = 1000000000)
public class OptionsApiImpl implements OptionsApi {

    @Autowired
    private OptionsMapper optionsMapper;

    @Override
    public List<Options> findOptionsList(Integer id) {

        QueryWrapper<Options> wrapper = new QueryWrapper<>();
        wrapper.eq("topic_id",id);
        return optionsMapper.selectList(wrapper);
    }

    @Override
    public Integer findByScore(int questionId, int optionId) {

        QueryWrapper<Options> wrapper = new QueryWrapper<>();
        wrapper.eq("id",optionId).eq("topic_id",questionId);
        Options options = optionsMapper.selectOne(wrapper);
        if (options==null){
            return 0;
        }
        return options.getScore();
    }
}
